package models

import (
	"time"
	"github.com/astaxie/beego/orm"
	"fmt"
)

type DeptProject struct {
	Id        string    `orm:"column(id);pk"`
	Type      int       `orm:"column(type)"`
	Seq       int       `orm:"column(seq)"`
	Remark    string    `orm:"column(remark);null"`
	Status    int       `orm:"column(status)"`
	Isdelete  int       `orm:"column(isdelete);null"`
	Ctime     time.Time `orm:"column(ctime);type(timestamp with time zone);null"`
	Creater   string    `orm:"column(creater)"`
	CreaterId string    `orm:"column(creater_id);null"`
	Utime     time.Time `orm:"column(utime);type(timestamp with time zone)"`
	Updater   string    `orm:"column(updater)"`
	UpdaterId string    `orm:"column(updater_id);null"`
	Params1   int       `orm:"column(params1)"`
	Params2   int       `orm:"column(params2)"`
	Params3   int       `orm:"column(params3)"`
	DeptId    string    `orm:"column(dept_id)"`
	DeptName  string    `orm:"column(dept_name)"`
}

func (m *DeptProject) TableName() string {
	return "ims_dept_project"
}

func init() {
	orm.RegisterModel(new(DeptProject))
}

func GetDeptProjects() ([]orm.Params, error) {
	o := orm.NewOrm()
	var l []orm.Params
	_, err := o.QueryTable(new(DeptProject)).Filter("Isdelete",0).Filter("Status",1).Values(&l)
	return l, err
}

// UpdateOuts updates Outs by Id and returns error if
// the record to be updated doesn't exist
func UpdateDeptProjectsById(m *DeptProject) (err error) {
	o := orm.NewOrm()
	v := DeptProject{Id: m.Id}
	// ascertain id exists in the database
	if err = o.Read(&v); err == nil {
		var num int64
		if num, err = o.Update(m); err == nil {
			fmt.Println("Number of records updated in database:", num)
		}
	}
	return
}
